
import 'package:flutter/cupertino.dart';

class AppLifecycleObserver extends WidgetsBindingObserver {

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);

    switch (state) {
      case AppLifecycleState.resumed:
      // 应用从后台回到前台
        print('App resumed');
        break;
      case AppLifecycleState.inactive:
      // 应用处于非活动状态
        print('App inactive');
        break;
      case AppLifecycleState.paused:
      // 应用进入后台
        print('App paused');
        break;
      case AppLifecycleState.detached:
      // 应用完全关闭
        print('App detached');
        break;
      case AppLifecycleState.hidden:
      // 应用完全关闭
        print('App hidden');
    }
  }
}